#Include ..\baseHandle.ahk


class GuessNum extends BaseHandle {

  static nullable := true
  static state := 0, max := 100, ans := 0, cnt := 0

  static Handle(parsed) {
    if GuessNum.state = 0 {
      GuessNum.state := 1, GuessNum.ans := Random(0, 100), GuessNum.cnt := 0
      return this.Succ('Start! 0 ~ 100')
    } else {
      if parsed.target = '' {
        parsed.target := Random(0, 100)
      }
      GuessNum.cnt++
      if parsed.target = GuessNum.ans {
        GuessNum.state := 0
        return this.Succ('Correct! Guessed in ' GuessNum.cnt ' times.')
      }
      return this.Fail(parsed.target ' too ' (parsed.target < GuessNum.ans ? 'low.' : 'high.'))
    }
  }

}